@echo off
setlocal
set "FRONT=%~dp0ai-display\lm-frontend"

echo [LM] Frontend dir: %FRONT%
if not exist "%FRONT%" goto :dir_err

where node >nul 2>nul
if errorlevel 1 goto :node_err
where npm >nul 2>nul
if errorlevel 1 goto :node_err

set "API_PROXY_TARGET=http://10.240.6.34:8080"

cd /d "%FRONT%"
if errorlevel 1 goto :dir_err

if not exist node_modules (
  echo [LM] Installing dependencies (npm install)...
  call npm install
  if errorlevel 1 goto :npm_err
)

echo [LM] Starting Next.js dev server on 0.0.0.0:3001 ????? http://10.240.6.34:3001/analysis?
call npm run dev -- -p 3001 -H 0.0.0.0
goto :eof

:dir_err
echo [LM] Frontend directory not found.
pause
exit /b 1

:node_err
echo [LM] Node.js/npm not found in PATH. Please install Node.js.
pause
exit /b 1

:npm_err
echo [LM] npm install failed.
pause
exit /b 1

